import Alert from "./Alert"
let loadingInstance = null
const instance = (opstion)=>{
  return new Promise((resolve,reject)=>{
      opstion.title = opstion.title || '加载中...'
      // getLoadingInstance(opstion);
       loadingInstance = loadingInstance || Alert.newInstance({
        title:opstion.title,
        handleOk:()=>{
          resolve()
          loadingInstance.destroy();
          loadingInstance = null;
        },
        handleCancel: ()=>{
          reject()
          loadingInstance.destroy();
          loadingInstance = null;
        }
      });
  })
}

export default instance

// let loadingInstance = 0;
// let getLoadingInstance = (opstion) => {
//   loadingInstance = loadingInstance || Alert.newInstance({
//     tip:opstion.tip,
//     handleCancel: ()=>{
//       opstion.handleCancel && opstion.handleCancel();
//       loadingInstance.destroy();
//       loadingInstance = null;
//     }
//   });
//   return loadingInstance;
// };


// export default {
//   open(opstion={}) {
//     opstion.tip = opstion.tip || '加载中...'
//     getLoadingInstance(opstion);
    
//   },
//   close() {
//     if (loadingInstance) {
//       loadingInstance.destroy();
//       loadingInstance = null;
//     }
//   },
// };